﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algobox.Objects.Finance.Prices
{
    public class OHLC : IOHLC
    {
        public OHLC()
        {
            _open = 0;
            _high = 0;
            _low = 0;
            _close = 0;
            _volume = 0;
            _timeStamp = DateTime.Now; 
        }

        public OHLC(double open, double high, double low, double close)
        {
            _open = open;
            _high = high;
            _low = low;
            _close = close;
            _volume = 0;
            _timeStamp = DateTime.Now;
        }

        public OHLC(double open, double high, double low, double close, ulong volume)
        {
            _open = open;
            _high = high;
            _low = low;
            _close = close;
            _volume = volume;
            _timeStamp = DateTime.Now;
        }

        public OHLC(double open, double high, double low, double close, ulong volume, DateTime timeStamp)
        {
            _open = open;
            _high = high;
            _low = low;
            _close = close;
            _volume = volume;
            _timeStamp = timeStamp;
        }

        public OHLC(string open, string high, string low, string close, string volume)
        {
            _open = double.Parse(open);
            _high = double.Parse(high);
            _low = double.Parse(low);
            _close = double.Parse(close);
            _volume = UInt64.Parse(volume);
            _timeStamp = DateTime.Now;
        }

        private double _open;
        private double _high;
        private double _low;
        private double _close;
        private ulong _volume;
        private DateTime _timeStamp;

        public double Open { get { return _open; } set { _open = value; } }
        public double High { get { return _high; } set { _high = value; } }
        public double Low { get { return _low; } set { _low = value; } }
        public double Close { get { return _close; } set { _close = value; } }
        public ulong Volume { get { return _volume; } set { _volume = value; } }
        public DateTime TimeStamp { get { return _timeStamp; } set { _timeStamp = value; } }

        public override string ToString()
        {
            return String.Format("{0}:{1}:{2}:{3}", Open, High, Low, Close);
        }

        public void Update(double price, ulong volume, DateTime timeStamp)
        {
            _timeStamp = timeStamp;
            _volume += volume;

            if (price > _high)
                _high = price;
            if (_low == 0 || price < _low)
                _low = price;
            
        }
    }
}
